package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KCourseCollect;
import com.ruoyi.qsng.service.IKCourseCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程收藏Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/courseCollect")
@Api(tags = "pc--课程收藏Controller")
public class KCourseCollectController extends BaseController {
    @Autowired
    private IKCourseCollectService kCourseCollectService;

    /**
     * 查询课程收藏列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询课程收藏列表")
    public TableDataInfo list(KCourseCollect kCourseCollect) {
        startPage();
        kCourseCollect.setIsCollect((long) 1);
        List<KCourseCollect> list = kCourseCollectService.selectKCourseCollectDataList(kCourseCollect);
        return getDataTable(list);
    }

    /**
     * 导出课程收藏列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:export')")
    @Log(title = "课程收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出课程收藏列表")
    public void export(HttpServletResponse response, KCourseCollect kCourseCollect) {
        List<KCourseCollect> list = kCourseCollectService.selectKCourseCollectList(kCourseCollect);
        ExcelUtil<KCourseCollect> util = new ExcelUtil<KCourseCollect>(KCourseCollect.class);
        util.exportExcel(response, list, "课程收藏数据");
    }

    /**
     * 获取课程收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取课程收藏详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kCourseCollectService.selectKCourseCollectById(id));
    }

    /**
     * 新增课程收藏
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:add')")
    @Log(title = "课程收藏", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增课程收藏")
    public AjaxResult add(@RequestBody KCourseCollect kCourseCollect) {
        return toAjax(kCourseCollectService.insertKCourseCollect(kCourseCollect));
    }

    /**
     * 修改课程收藏
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:edit')")
    @Log(title = "课程收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改课程收藏")
    public AjaxResult edit(@RequestBody KCourseCollect kCourseCollect) {
        return toAjax(kCourseCollectService.updateKCourseCollect(kCourseCollect));
    }

    /**
     * 删除课程收藏
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseCollect:remove')")
    @Log(title = "课程收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除课程收藏")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kCourseCollectService.deleteKCourseCollectByIds(ids));
    }
}
